import {getUrl} from './mixin'
import axios from 'axios'

const DETAIL_SHOW = 'DETAIL_SHOW'
const DETAIL_HIDE = 'DETAIL_HIDE'
const DETAIL_DATA = 'DETAIL_DATA'
const initState ={
  isDetails:false,
  data:[]
}
export function detail(state=initState,action){
  switch(action.type){
    case DETAIL_SHOW:
      return {...state,isDetails:true,id:action.id}
    case DETAIL_HIDE:
      return {...state,isDetails:false}
    case DETAIL_DATA:
      return {...state,data:action.payload}
    default:
      return state
  }
}

export function detailShow(id){
  return {type:DETAIL_SHOW,id}
}
export function detailHide(){
  return {type:DETAIL_HIDE}
}
export function detailData(data){
  return {type:DETAIL_DATA,payload:data}
}
export function getDetail(){
  return dispatch =>{
    axios.post(`/api/visualData/queryTopicList?id=${getUrl()}&pageNum=1&pageSize=20`)
      .then(res => {
        if(res.status === 200){
          dispatch(detailData(res.data.data))
        }
      })
  }
}